//
// Created by 12345 on 2025/2/19.
//

#ifndef DOG58_CONNECT_MANAGER_H
#define DOG58_CONNECT_MANAGER_H

#include "string"
#include "cstdlib"
#include "gazella/interface_timer.h"
#include "gazella/udp_server.h"
#include "gazella/udp_client.h"
#include "utils.h"
#include "report_bean.h"
#include "command_bean.h"
#include <chrono>
#include <thread>
#include "daf/DeviceAgentModel.pb.h"
#include "daf/daf_model.h"
#include "gazella/logger.h"
#include "config_model.h"

class ConnectManager {
public:
    static ConnectManager* getInstance();
    void init();
private:
    ConnectManager() = default;
    ~ConnectManager() = default;
    const std::string remoteAddr = "192.168.1.158";//58狗综控地址;
    Gazella::UdpClient commandClient;
    const int commandPort = 35858;//控狗指令端口
    Gazella::UdpClient heartClient;
    const int heartPort = 36060;//综控心跳端口
    Gazella::UdpServer agentServer;
    const std::string hashRateAddr = "192.168.1.101";//设备代理板子地址必须是这个,58狗总控板是给这个地址上报数据的
    const std::string localAddr="192.168.1.101";//监听本地所有ip段
    const int localReportPort = 35959;//监听综控板上报数据
    std::chrono::system_clock::time_point receiveReportTime;
    std::vector<std::shared_ptr<std::thread>> taskCache;

    bool initUdp();
    void keepHeart();
    void keepCommand();
    void keepStatusCheck();
    void parseReport(const std::string &remote_host, int remote_port, std::string &msg);
    bool checkHead(std::string &msg);


};

#endif //DOG58_CONNECT_MANAGER_H
